package com.retail.system.mapper;

import com.retail.core.common.CommonMapper;
import com.retail.system.entity.po.AdminPo;
import com.retail.system.entity.request.AdminRequest;
import com.retail.system.entity.vo.AdminStatisticsPersonVo;
import com.retail.system.entity.vo.AdminVo;
import com.retail.team.entity.vo.RetailTeamAddSpVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 系统管理员Mapper
 *
 * @author administrator
 * @since 2019-05-25
 */
@Mapper
public interface AdminMapper extends CommonMapper<AdminRequest, AdminVo> {

    /**
     * 更新密码
     *
     * @param id      编号
     * @param newPass 新密码
     * @return 返回是否修改成功 1- 是 0- 否
     */
    int updatePassById(@Param("id") Long id, @Param("newPass") String newPass);

    /**
     * 删除用户
     *
     * @param id 编号
     * @return 返回删除是否成功标志 0- 否 1-是
     */
    int deleteById(@Param("id") Integer id);

    /**
     * 根据ID更新admin信息
     *
     * @param adminPo
     * @return
     */
    int updateById(AdminPo adminPo);

    /**
     * 批量更新stateFlag的状态
     *
     * @param idsList
     * @param statusFlag
     * @return
     */
    int updateStatusFlagByIds(@Param("idsList") List<Long> idsList, @Param("statusFlag") Integer statusFlag);

    /**
     * 更加用户名称得到用户信息
     *
     * @param usename
     * @return
     */
    AdminPo getModelByUserName(@Param("username") String usename);

    @Select("select count(1) from sys_admin a where a.phone = #{mobile}  and a.open_id  = #{openId} and a.audit_status = 1 and a.del_flag  = 0 ")
    Integer checkMobileAndOpenIdIsRegister(@Param("mobile") String mobile, @Param("openId") String openId);

//    @Select("select count(1) from sys_admin a where a.phone = #{mobile} and (a.open_id is null or length(open_id) = 0)  and a.audit_status = 1 and a.del_flag  = 0")
    @Select("select count(1) from sys_admin a where a.phone = #{mobile}")
    Integer checkMobileIsRegister(@Param("mobile") String mobile);

    @Select("select count(1) from sys_admin a where a.open_id = #{openId}  and a.audit_status = 1 and a.del_flag  = 0")
    Integer checkOpenIdIsRegister(@Param("openId") String openId);

    @Select("select count(1) from sys_admin a where a.username = #{username}  and a.del_flag  = 0")
    Integer checkUsernameIsUse(@Param("username") String username);

    AdminVo getUserByOpenId(@Param("openId") String openId);

    /**
     * 更新用户名下商户信息
     * @param id
     * @return
     */
    Integer updateOwerShop(@Param("id") Long id);

    List<AdminVo> getChildByParentId(@Param("parentId") Long parentId);

    List<AdminVo> childAdminByParentIdAndId(@Param("adminId") Long adminId);

    List<AdminVo> findAllAdminsByAuditStatus(@Param("auditStatus") Integer auditStatus);

    /**
     * 得到用户下级推荐
     * @param parentId
     * @param auditStatus
     * @return
     */
    List<AdminVo> findAllAdminsByParentIdAndAuditStatus(@Param("parentId") Long parentId,@Param("auditStatus") Integer auditStatus);

    Integer updateGroupShop(@Param("id") Long id, @Param("groupShopCount") Integer groupShopCount);

    Integer examineVerify(@Param("request") AdminRequest request);

    AdminVo getModelByPoiId(@Param("poiId") String poiId);

    @Update("update sys_admin set url_zm = #{urlZm} , url_fm=#{urlFm} where id = #{id}")
    Integer authInfo(@Param("urlZm") String urlzm, @Param("urlFm") String urlFm, @Param("id") Long id);

    List<AdminVo> noParentIdAdmin();

    RetailTeamAddSpVo findTeamSpLimit1(@Param("adminId") Long adminId);

    Integer updateParenIdById(@Param("id") Long id, @Param("parentId") Long parentId);

    Integer updateAdminLevelByAdminId(@Param("adminId") Long adminId, @Param("adminLevel") Long adminLevel);

    AdminVo getUserByPromoCode(@Param("promoCode") String promoCode);

    Integer updatePromoCodeUrlById(@Param("id") Long id, @Param("promoCodeUrl") String promoCodeUrl);

    List<AdminVo> myteams(@Param("adminId") Long adminId);

    List<AdminVo> getModelByParentAndAdminLevel(@Param("parentId") Long parentId, @Param("adminLevel") Long adminLevel);

    List<AdminVo> findAdminsByUserTypeAndAdminLevel(@Param("userType") Integer userType, @Param("adminLevel") Integer adminLevel);

    Integer updateUpgradeLevel(AdminVo admin);

    AdminStatisticsPersonVo statisticsPerson(@Param("id") Long id);

    Integer allYwy();


    Integer updateCity(@Param("id") Long id, @Param("city") String city);
}
